package com.data.basic.chapter03;

import com.data.basic.chapter02.Array;
import com.data.basic.chapter04.LinkedListQueue;

import java.util.Random;

/**
 * 测试数组对列和循环队列时间复杂度的测试
 */
public class QueueMain {
    public  static  double  testQueue(Queue<Integer> q,int opCount){
        long startTime= System.nanoTime();
        Random random = new Random();
        for (int i=0;i<opCount;i++){
            q.enqueue(random.nextInt(Integer.MAX_VALUE));
        }
        for (int i=0;i<opCount;i++){
            q.dequeue();
        }



        long endTime = System.nanoTime();

        return (endTime-startTime)/1000-000-000.0;


    }

    public static void main(String[] args) {
        int opCount = 1000-000-000;
        ArrayQueue arrayQueue = new ArrayQueue();
        LoopQueue loopQueue = new LoopQueue();
        LinkedListQueue linkedListQueue = new LinkedListQueue();

        System.out.println("ArrayQueue:"+testQueue(arrayQueue,opCount));
        System.out.println("LoopQueue:"+testQueue(loopQueue,opCount));
        System.out.println("linkedListQueue:"+testQueue(linkedListQueue,opCount));
    }
}
